<script>
  import { userApi } from '@/http/userApi.js';
  import { USER_TOKEN } from '@/constants/local-storage-key-const'
  import store from './store'
  export default {
    onLaunch: async function() {
	  this.setUserInfo()
    },
    onShow: function() {
      console.log('App Show');
    },
    onHide: function() {
      console.log('App Hide');
    },
	methods:{
		setWxHeader(){
			let statusBarHeight = uni.getWindowInfo().statusBarHeight;
			// #ifdef MP 
			let menuButtonHeight = uni.getMenuButtonBoundingClientRect().height;
			let titleBarWidth = uni.getWindowInfo().windowWidth - uni.getMenuButtonBoundingClientRect().width - (uni.getWindowInfo().windowWidth - uni.getMenuButtonBoundingClientRect().right) * 2;
			let titleBarHeight = (uni.getMenuButtonBoundingClientRect().top - statusBarHeight) * 2 + menuButtonHeight;
			store.commit('setWxHeader',{
				'statusBarHeight':statusBarHeight,
				'menuButtonHeight':menuButtonHeight,
				'titleBarWidth':titleBarWidth,
				'titleBarHeight':titleBarHeight
			})
			// #endif
			// #ifdef APP
			store.commit('setStatusBarHeight',statusBarHeight)
			// #endif
		},
		setUserInfo() {
			const token = uni.getStorageSync(USER_TOKEN)
			if(token){
				userApi.getUserInfo().then((res)=>{
					store.commit('setUserInfo',res)
				}).catch((e)=>{
					uni.navigateTo({
						url:'/pages/login/login'
					})
				})
			}else{
				uni.navigateTo({
					url:'/pages/login/login'
				})
			}
		},
	},
  };
</script>

<style lang="scss">
  /*每个页面公共css */
  @import './theme/iconfont.css';
  @import './theme/index.css';
</style>